home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / PARSING.SWG / 0002_PARSEWRD.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  133 lines

  1. Program PARSER;
  2.  
  3. {The Object of this Program is to accept a sentence from the user then to break the
  4.  sentence into its Component Words and to display each Word on a separate line.
  5. }
  6.  
  7. Uses Crt; {Required by Turbo Pascal}
  8.  
  9. Const
  10.   maxWord     = 15;
  11.   maxsentence = 15;
  12.   space       = CHR(32);
  13.   first       = 1;
  14.  
  15. Type
  16.   Strng = Array[1..maxWord] of Char;
  17.   Word  = Record
  18.     body   : Strng;
  19.     length : Integer
  20.   end;
  21.  
  22. Var
  23.   sentence                 : Array[1..maxsentence] of Word;
  24.   row, col, nextcol, count : Integer;
  25.   demarker                 : Boolean;
  26.   ans                      : Char;
  27.  
  28. Procedure SpaceTrap;
  29. { Insures that there is ony 1 space between Words     }
  30. begin
  31.   Repeat
  32.     READ(sentence[row].body[first])
  33.   Until sentence[row].body[first] <> space
  34. end;
  35.  
  36. Procedure StringWrite(Var phrase : Word);
  37. {Writes only the required length of each Character String.
  38. This is required when using 32 col. mode.}
  39. Var
  40.   letter : Integer;
  41. begin
  42.          For letter := first to phrase.length do
  43.            Write(phrase.body[letter])
  44.        end; {Procedure StringWrite}
  45.  
  46.      Procedure StringRead;
  47.       Var I : Integer;
  48.       begin
  49.       {
  50.        Intitialize the Variables
  51.       }
  52.         count    := 1;
  53.         row      := first;
  54.         col      := first;
  55.         nextcol  := col + 1;
  56.         demarker := False;
  57.         For I := first to maxsentence do
  58.             sentence[I].length := 1;
  59.         Write('Type a sentence >  ');
  60.         {READLN;} {Clears the buffer of EOLN}
  61.                   {Required by HiSoft Pascal}
  62.             While (not EOLN) and (row < maxsentence) do
  63.                 begin
  64.                    READ(sentence[row].body[col]);
  65.                    if sentence[row].body[first] = space then SpaceTrap;
  66.                    if sentence[row].body[col] = space then
  67.                       demarker := True;
  68.                    if (not demarker) and (nextcol < maxWord) then
  69.                        begin
  70.                          col     := col + 1;
  71.                          nextcol := nextcol + 1
  72.                        end
  73.                     else
  74.                       begin
  75.                         sentence[row].length := col;
  76.                         count                := count + 1;
  77.                         row                  := row + 1;
  78.                         col                  := first;
  79.                         nextcol              := col + 1;
  80.                         demarker             := False
  81.                       end; {if...then...else}
  82.         if EOLN then sentence[row].length := col - 1
  83.         {Accounts For the last Word entered less the EOLN marker.}
  84.                 end {While loop}
  85.       end; {Procedure StringRead}
  86.  
  87.      Procedure PrintItOut;
  88.       Var
  89.           subsequent : Integer;
  90.       begin
  91.           subsequent := first + 1;
  92.           Write('Parsing > ');
  93.           StringWrite(sentence[first]);
  94.           WriteLN;
  95.           if count >= subsequent then
  96.               begin
  97.                   For row := subsequent to count do
  98.                       begin
  99.                           Write('          ');
  100.                           StringWrite(sentence[row]);
  101.                           WriteLN
  102.                       end
  103.               end
  104.        end; {Procedure PrintItOut}
  105.  
  106.      Procedure SongandDance;
  107.       begin
  108.           {PAGE;} {HiSoft Pascal = Turbo Pascal ClrScr}
  109.           ClrScr;
  110.           WriteLN('           Parser');
  111.           WriteLN;
  112.           WriteLN('    Program By David Solly');
  113.           WriteLN;
  114.           WriteLN('   The Object of this Program');
  115.           WriteLN('is to accept a sentence from');
  116.           WriteLN('the user then to break the');
  117.           WriteLN('sentence down into its');
  118.           WriteLN('Component Words and to display');
  119.           WriteLN('each Word on a seperate line.');
  120.           WriteLN;
  121.           WriteLN;
  122.       end; {Procedure SongandDance}
  123.  
  124.      begin {Main Program}
  125.      SongandDance;
  126.      StringRead;
  127.      WriteLN;
  128.      PrintItOut;
  129.      WriteLN;
  130.      WriteLN('end of Demonstration.');
  131.      READLN(ans);
  132.      end. {Main Program}
  133.